﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;

namespace DotNetX
{
    public static class NameValueCollectionExtensions
    {
        public static T GetValue<T>(this NameValueCollection col, string name, T defaultValue)
        {
            if(String.IsNullOrEmpty(name))
                throw new ArgumentNullException("'name' is null.");

            string value = col[name];

            if (String.IsNullOrEmpty(value))
                return defaultValue;
            else
                return ConvertExtensions.ToType<T>(value);
        }
    }
}
